var Home = {
    departCode : $("#departCode").val(),
    departDesc : $("#departDesc").val()==null||$("#departDesc").val()==""?"全院":$("#departDesc").val(),
    tableIndex: $("#departCode").val()==null||$("#departCode").val()==""?"科室":"主治医师" //表格第一列描述
};
$(function () {
    //科室
    $('#depart').combobox({
        data:$.parseJSON($("#departMap").val()),
        valueField:'value',
        textField:'text'
        //onSelect:ManageIndex.departChange
    });
    //院区
    $('#office').combobox({
        data:$.parseJSON($("#officeMap").val()),
        valueField:'value',
        textField:'text',
        defaultFilter: 6,
        onSelect:Home.officeChange,
        onLoadSuccess: function () { //加载完成后,val[0]写死设置选中第一项
            var val = $(this).combobox("getData");
            if(val.length==2){//如果就一个院区 加上全部=2
                $(this).combobox("setValue", val[1].value);
                Home.officeChange(val[1]);
                $("#oneOffice").val("yes");
            }else{
                $(this).combobox("setValue", "");
                $("#oneOffice").val("no");
            }
        }
    });
    //病种
    $('#qcEntity').combobox({
        data:$.parseJSON($("#entityMap").val()),
        valueField:'value',
        textField:'text',
        defaultFilter: 6,
        onLoadSuccess: function () { //加载完成后,val[0]写死设置选中第一项
            var val = $(this).combobox("getData");
            $(this).combobox("setValue", val[1].value);
        }
        //onSelect:ManageIndex.departChange
    });
    /*$('#startDate').datebox('setValue',"");
    $('#endDate').datebox('setValue',"");*/
    //年
    $('#qcYear').combobox({
        data:$.parseJSON($("#yearMap").val()),
        valueField:'value',
        textField:'text',
        defaultFilter: 6,
        onLoadSuccess: function () { //加载完成后,val[0]写死设置选中第一项
            var val = $(this).combobox("getData");
            $(this).combobox("setValue", val[0].value);
        }
        //onSelect:ManageIndex.departChange
    });
    //月
    $('#qcMonth').combobox({
        data:$.parseJSON($("#monthMap").val()),
        valueField:'value',
        textField:'text',
        defaultFilter: 6,
        //onSelect:ManageIndex.departChange
    });

    //Home.initTopMiddle();//加载主页顶部和中部的数据
    Home.initBottomTable();//加载主页低部表格数据
    //主页最上面文字描述
    $("#homeHtmlDesc").panel({title:"单病种质量指标统计"});
    //表格上面文字描述
    var desc = $("#qcEntity").combobox("getText");
    $("#homeTableDesc").panel({title:desc +"指标表格数据"});
    //绑定顶部和中部蓝色数字的点击事件
    $(".homeCaseDeatil").click(function(){
        var _this = $(this);
        var key = _this.attr("id");
        /*var desc = _this.parent().prev().html();//父级的上一个同级元素*/
        var im_content=document.getElementById(key).parentNode;;
        var descText = im_content.innerText;
        var desc = descText.split("：")[0];
        Home.homeKeyDetail(key,desc,1);
    });
    $(".homeCaseDeatil2").click(function(){
        var _this = $(this);
        var key = _this.attr("id");
        var desc = _this.parent().prev().html();//父级的上一个同级元素
        Home.homeKeyDetail(key,desc,2);
    });
});

/**
 * //根据父级机构 查询子机构
 */
Home.officeChange = function(that){
    var ajax = new $ax("/sds/common/deptListByHospId", function(data){
        $('#depart').combobox({
            data:data,
            valueField:'value',
            textField:'text',
            defaultFilter: 6,
            onLoadSuccess: function () { //加载完成后,val[0]写死设置选中第一项
                $(this).combobox("setValue", "");
            }
        });
    },function(data){
        layer.msg("查询失败!" + data.responseJSON.message + "!",{icon: 2});
    });
    ajax.set({"hospID":that.value,"id":"depart"});
    ajax.start();
}

Home.search = function(){
    Home.initBottomTable();
};

/**
 * 加载主页底部表格数据
 */
Home.initBottomTable = function(){
    //获取主页底部表格数据
    var params = {};
    var ajax = new $ax("/api/selectSdsIndsta", function (data) {
        $('#departmentTable').bootstrapTable("destroy");//先销毁原来的表格
        Home.drawTable(data.tableDates);
        //Home.writeTopData(data);
        Home.drawMiddleChart(data.chartDatas);
        Home.drawMiddleChart2(data.chartDatas2);
        Home.drawMiddleChart3(data.chartDatas3);
        //合并单元格
        /*mergeCells(data.tableDates, "locDesc", 1, $('#departmentTable'));*/
        $("#departmentTable > tbody td").each(function(index){//鼠标悬浮 显示表格数据
            $(this).attr("title",$(this).text());
        });
    }, function (data) {
    });
    /*if ($('#startDate').datebox('getValue') != ""){
        params.startDate = $('#startDate').datebox('getValue')+" 00:00:00";//开始日期
        params.endDate = $('#endDate').datebox('getValue')+" 23:59:59";//开始日期
    } else {
        params.startDate = "";//开始日期
        params.endDate = "";//开始日期
    }*/
    params.year = $("#qcYear").combobox("getValue");//年
    params.month = $("#qcMonth").combobox("getValue");//月
    params.office = $("#office").combobox("getValue");
    params.depart = $("#depart").combobox("getValue");
    params.qcEntity = $("#qcEntity").combobox("getValue");
    ajax.set(params);
    ajax.start();
};

/**
 * 写主页顶部数据
 */
Home.writeTopData = function(data){
    /*$("#inHospitalEval").html(data.inHospitalEval);
    $("#inHospitalEvalRate").html(data.inHospitalEvalRate);
    $("#riskEvalNum").html(data.riskEvalNum);
    $("#bloodEvalNum").html(data.bloodEvalNum);
    $("#noPrevent").html(data.noPrevent);
    $("#noPreventRate").html(data.noPreventRate);
    $("#middleDanger").html(data.middleDanger);
    $("#middleDangerRate").html(data.middleDangerRate);
    $("#highDanger").html(data.highDanger);
    $("#highDangerRate").html(data.highDangerRate);
    $("#suspectPe").html(data.suspectPe);
    $("#suspectPeRate").html(data.suspectPeRate);
    $("#suspectDvt").html(data.suspectDvt);
    $("#suspectDvtRate").html(data.suspectDvtRate);
    $("#suspectOther").html(data.suspectOther);
    $("#suspectOtherRate").html(data.suspectOtherRate);
    $("#confirmPe").html(data.confirmPe);
    $("#confirmPeRate").html(data.confirmPeRate);
    $("#confirmDvt").html(data.confirmDvt);
    $("#confirmDvtRate").html(data.confirmDvtRate);
    $("#confirmOther").html(data.confirmOther);
    $("#confirmOtherRate").html(data.confirmOtherRate);
    $("#allCase").html(data.allCase);*/
    $("#todayUp").html(data.todayUp);
    $("#todayUpRate").html(data.todayUpRate);
    $("#monthUp").html(data.monthUp);
    $("#monthUpRate").html(data.monthUpRate);
    $("#yearUp").html(data.yearUp);
    $("#yearUpRate").html(data.yearUpRate);
    $("#totalUp").html(data.totalUp);
    /*$("#totalUpRate").html(data.totalUpRate);*/
    $("#upLoc").html(data.upLoc);
    $("#upEntity").html(data.upEntity);
    $("#upEntityRate").html(data.upEntityRate);
    $("#upTimeRate").html(data.upTimeRate);
};
/**
 * 画中部图形
 */
Home.drawMiddleChart = function(data){
    /*echarts.init($("#analysisChart")[0]).dispose();
    var qcEntity = $("#qcEntity").combobox("getText");
    var lines = [
        {desc:qcEntity+'指标完成率',data:[],code:'confirmRate'}
    ];
    var chartParams = {
        //backgroundColor : '#f2f2f2',
        isHorizontal : false,
        legendShow : false,
        showLabel : true,
        yAxisName : '%',//y轴单位
        legend:{
            show : false
        },
        isDataZoom:false,//是否显示缩放
        titleLeft:'center',//标题位置
        xAxisInterval:0,//坐标轴刻度标签的显示间隔，在类目轴中有效。默认会采用标签不重叠的策略间隔显示标签。可以设置成 0 强制显示所有标签
        rotate:50,//x轴数据偏移角度
        grid:{
            containLabel: true, //注意加上，否则axisLabel有可能显示会不全
            top:"35px",
            left:"20px",
            right:"20px",
            bottom:"50px"
        },
        label:{
            show:true,
            position:'top'
        }
    };
    //lineChartVte($("#analysisChart"), lines, chartDatas,null,null,chartParams);
    barChartVte($("#analysisChart"), lines, chartDatas["confirmRate"], qcEntity+'指标完成率',null,chartParams);*/
    var lines = [
        {desc:'上报例数',data:[],code:'upNum'}
    ];
    var chartParams = {
        backgroundColor : '#f2f2f2',//背景颜色
        isHorizontal : false,
        yAxisName : '单位:例',//y轴单位
        formatterFunc : function(params){
            var backStr = "";
            var relVal = params[0].name;
            backStr += relVal + "<br>";
            for (var i = 0;i < params.length; i++) {
                backStr += params[i].marker+params[i].seriesName + "：" +params[i].value+ "例<br>";
            }
            return backStr;
        },
        titleShow:false,
        isDataZoom:false,//是否显示缩放
        legendShow : false,
        legendPosition : 'top',
        gridLeft:"5px",
        gridRight:"5px",
        gridTop:"15px",
        gridBottom:"10px",
        rotate:60,//x轴数据偏移角度
        showLabel : true,
        legend:{
            show : false
        }
    };
    lineChartVte($("#upNumChart"), lines, data,null,null,chartParams);
};

Home.drawMiddleChart2 = function(data) {
    var lines = [
        {desc:'上报例数',data:[],code:'confirmRate2'}
    ];
    var chartParams = {
        backgroundColor : '#f2f2f2',//背景颜色
        isHorizontal : false,
        yAxisName : '单位:例',//y轴单位
        formatterFunc : function(params){
            var backStr = "";
            var relVal = params[0].name;
            backStr += relVal + "<br>";
            for (var i = 0;i < params.length; i++) {
                backStr += params[i].marker+params[i].seriesName + "：" +params[i].value+ "例<br>";
            }
            return backStr;
        },
        titleShow:false,
        isDataZoom:false,//是否显示缩放
        legendShow : false,
        legendPosition : 'top',
        gridLeft:"5px",
        gridRight:"5px",
        gridTop:"15px",
        gridBottom:"10px",
        rotate:60,//x轴数据偏移角度
        showLabel : true,
        legend:{
            show : false
        }
    };
    lineChartVte($("#admDaysChart"), lines, data,null,null,chartParams);
}

Home.drawMiddleChart3 = function(data) {
    var lines = [
        {desc:'上报例数',data:[],code:'confirmRate3'}
    ];
    var chartParams = {
        backgroundColor : '#f2f2f2',//背景颜色
        isHorizontal : false,
        yAxisName : '单位:例',//y轴单位
        formatterFunc : function(params){
            var backStr = "";
            var relVal = params[0].name;
            backStr += relVal + "<br>";
            for (var i = 0;i < params.length; i++) {
                backStr += params[i].marker+params[i].seriesName + "：" +params[i].value+ "例<br>";
            }
            return backStr;
        },
        titleShow:false,
        isDataZoom:false,//是否显示缩放
        legendShow : false,
        legendPosition : 'top',
        gridLeft:"5px",
        gridRight:"5px",
        gridTop:"15px",
        gridBottom:"10px",
        rotate:60,//x轴数据偏移角度
        showLabel : true,
        legend:{
            show : false
        }
    };
    lineChartVte($("#entityFeeChart"), lines, data,null,null,chartParams);
}

/**
 * 表格的表头
 */
Home.columns = [
    [
    {title: '出院时间', field: 'dishDate', align: 'left', valign: 'middle', sortable: true,width:80,rowspan: 2,
        footerFormatter:function(value){
            return "总计";
        }
    },
        {title: '出院人数', field: 'num', align: 'left', valign: 'middle', sortable: true,width:80,rowspan: 2,
            /*formatter:function(value,row,index){
                return "<a onclick='Home.homeDepartDetail(&apos;"+row.dishDate+"&apos;,&apos;"+""+"&apos;)'>"+value+"</a>";
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"num");
            }
        },
    {
        title: '到医院后首剂双联抗血小板药物使用情况', align: 'center', colspan: 2,width:300,
    },
    {
        title: '左心室射血分数', align: 'center', colspan: 4,width:600,
    },
    {
        title: '再灌注治疗', align: 'center', colspan: 2,width:300,
    },
    {
        title: 'β受体阻滞剂使用情况', align: 'center', colspan: 1,width:150,
    },
    {
        title: '住院期间β受体阻滞剂、双联抗血小板药物、血管紧张素转化酶抑制剂(ACEI)或 血管紧张素受体阻断剂(ARB)、他汀类药物使用情况', align: 'center', colspan: 4,width:600,
    },
    {
        title: '出院时β受体阻滞剂、双联抗血小板药物、ACEI 或 ARB、他汀类药物、醛固酮受体拮抗剂使用情况', align: 'center', colspan: 5,width:750,
    },
        {
            title: '住院总费用（元）', align: 'center', colspan: 1,width:150,
        },
        {
            title: '手术治疗费用（元）', align: 'center', colspan: 1,width:150,
        },
        {
            title: '手术用一次性医用材料费用（元）', align: 'center', colspan: 1,width:150,
        },
    {
        title: '住院天数', align: 'center', colspan: 1,width:150,
    },

    {
        title: '药费（元）', align: 'center', colspan: 1,width:150,
    }
    ],
    [
        {title: '使用阿司匹林（有禁忌症使用氯吡格雷 ）占比', field: 'sTEMI1', align: 'left', valign: 'middle', sortable: true,width:150,
            /*formatter:function(value,row,index){
                return "<a onclick='Home.homeKeyDetailTable(&apos;"+""+"&apos;,&apos;"+row.entityDesc+"符合例数"+"&apos;,&apos;"+row.entityId+"&apos;)'>"+value+"</a>";
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMI1");
            }
        },
        {title: '到院10分钟内完成心电图检查占比', field: 'sTEMI1', align: 'left', valign: 'middle', sortable: true,width:150,
            /*formatter:function(value,row,index){
                return "<a onclick='Home.homeKeyDetailTable(&apos;"+""+"&apos;,&apos;"+row.entityDesc+"符合例数"+"&apos;,&apos;"+row.entityId+"&apos;)'>"+value+"</a>";
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMI1");
            }
        },
        {title: '实施首次CDFA检查', field: 'sTEMI21', align: 'left', valign: 'middle', sortable: true,width:150,
            /*formatter:function(value,row,index){
                if (value == "y"){
                    return "是";
                }else if (value == "n"){
                    return "否";
                }
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMINum21");
            }
        },
        {title: '实施首次X线胸片检查', field: 'sTEMI22', align: 'left', valign: 'middle', sortable: true,width:150,
            /*formatter:function(value,row,index){
                if (value == "y"){
                    return "是";
                }else if (value == "n"){
                    return "否";
                }
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMINum22");
            }
        },
        {title: '完成GRACE评估', field: 'sTEMI23', align: 'left', valign: 'middle', sortable: true,width:150,
           /* formatter:function(value,row,index){
                if (value == "y"){
                    return "是";
                }else if (value == "n"){
                    return "否";
                }
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMINum23");
            }
        },
        {title: '完成CRUSADE评估', field: 'sTEMI24', align: 'left', valign: 'middle', sortable: true,width:150,
            /*formatter:function(value,row,index){
                if (value == "y"){
                    return "是";
                }else if (value == "n"){
                    return "否";
                }
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMINum24");
            }
        },
        {title: 'STEMI确诊报告至溶栓时间', field: 'sTEMI31', align: 'left', valign: 'middle', sortable: true,width:150,
            /* formatter:function(value,row,index){
                 return "<a onclick='Home.homeDepartDetail(&apos;"+""+"&apos;,&apos;"+""+"&apos;)'>"+value+"</a>";
             },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMI31");
            }
        },
        {title: 'STEMI至PCI导丝通过梗死相关动脉时间', field: 'sTEMI32', align: 'left', valign: 'middle', sortable: true,width:150,
            /*formatter:function(value,row,index){
                return "<a onclick='Home.homeKeyDetail(&apos;inHospitalEval&apos;,&apos;"+""+
                    "入院审核&apos;,&apos;"+""+"&apos;,2)'>"+value+"&nbsp;&nbsp;("+MathMethod(row.deathNum,row.consistentNum)+")</a>";
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMI32");
            }
        },
        {title: '首剂β-受体阻滞剂', field: 'sTEMI4', align: 'left', valign: 'middle', sortable: true,width:150,
            /*formatter:function(value,row,index){
                if (value == "y"){
                    return "是";
                }else if (value == "n"){
                    return "否";
                }
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMINum4");
            }
        },
        {title: '住院期间双联抗血小板药物', field: 'sTEMI51', align: 'left', valign: 'middle', sortable: true,width:150,
            /*formatter:function(value,row,index){
                if (value == "y"){
                    return "是";
                }else if (value == "n"){
                    return "否";
                }
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMINum51");
            }
        },
        {title: '住院期间β受体阻滞剂', field: 'sTEMI52', align: 'left', valign: 'middle', sortable: true,width:150,
            /*formatter:function(value,row,index){
                if (value == "y"){
                    return "是";
                }else if (value == "n"){
                    return "否";
                }
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMINum52");
            }
        },
        {title: '住院期间ACEI或ARB', field: 'sTEMI53', align: 'left', valign: 'middle', sortable: true,width:150,
           /* formatter:function(value,row,index){
                if (value == "y"){
                    return "是";
                }else if (value == "n"){
                    return "否";
                }
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMINum53");
            }
        },
        {title: '住院期间他汀类药物', field: 'sTEMI54', align: 'left', valign: 'middle', sortable: true,width:150,
            /*formatter:function(value,row,index){
                if (value == "y"){
                    return "是";
                }else if (value == "n"){
                    return "否";
                }
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMINum54");
            }
        },
        {title: '出院时双联抗血小板药物', field: 'sTEMI61', align: 'left', valign: 'middle', sortable: true,width:150,
            /*formatter:function(value,row,index){
                if (value == "y"){
                    return "是";
                }else if (value == "n"){
                    return "否";
                }
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMINum61");
            }
        },
        {title: '出院时β受体阻滞剂', field: 'sTEMI62', align: 'left', valign: 'middle', sortable: true,width:150,
            /*formatter:function(value,row,index){
                if (value == "y"){
                    return "是";
                }else if (value == "n"){
                    return "否";
                }
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMINum62");
            }
        },
        {title: '出院时ACEI或ARB', field: 'sTEMI63', align: 'left', valign: 'middle', sortable: true,width:150,
            /*formatter:function(value,row,index){
                if (value == "y"){
                    return "是";
                }else if (value == "n"){
                    return "否";
                }
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMINum63");
            }
        },
        {title: '出院时他汀类药物', field: 'sTEMI64', align: 'left', valign: 'middle', sortable: true,width:150,
            /*formatter:function(value,row,index){
                if (value == "y"){
                    return "是";
                }else if (value == "n"){
                    return "否";
                }
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMINum64");
            }
        },
        {title: '出院时醛固酮受体拮抗剂', field: 'sTEMI65', align: 'left', valign: 'middle', sortable: true,width:150,
            /*formatter:function(value,row,index){
                if (value == "y"){
                    return "是";
                }else if (value == "n"){
                    return "否";
                }
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMINum65");
            }
        },
        {title: '平均住院日费用', field: 'sTEMI7', align: 'left', valign: 'middle', sortable: true,width:150,
            /*formatter:function(value,row,index){
                return "<a onclick='Home.homeDepartDetail(&apos;"+""+"&apos;,&apos;"+""+"&apos;)'>"+value+"</a>";
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMI7");
            }
        },
        {title: '平均手术治疗费用', field: 'sTEMI9', align: 'left', valign: 'middle', sortable: true,width:150,
            /*formatter:function(value,row,index){
                return "<a onclick='Home.homeDepartDetail(&apos;"+""+"&apos;,&apos;"+""+"&apos;)'>"+value+"</a>";
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMI9");
            }
        },
        {title: '平均手术用一次性医用材料费用', field: 'sTEMI10', align: 'left', valign: 'middle', sortable: true,width:150,
            /*formatter:function(value,row,index){
                return "<a onclick='Home.homeDepartDetail(&apos;"+""+"&apos;,&apos;"+""+"&apos;)'>"+value+"</a>";
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMI10");
            }
        },
        {title: '平均住院日', field: 'sTEMI11', align: 'left', valign: 'middle', sortable: true,width:150,
            /*formatter:function(value,row,index){
                return "<a onclick='Home.homeDepartDetail(&apos;"+""+"&apos;,&apos;"+""+"&apos;)'>"+value+"</a>";
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMI11");
            }
        },
        {title: '平均药费', field: 'sTEMI8', align: 'left', valign: 'middle', sortable: true,width:150,
            /*formatter:function(value,row,index){
                return "<a onclick='Home.homeDepartDetail(&apos;"+""+"&apos;,&apos;"+""+"&apos;)'>"+value+"</a>";
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMI8");
            }
        },
        {title: '实施首次超声心动图(CDFA)检查数量', field: 'sTEMINum21', align: 'left', valign: 'middle', sortable: true,width:150, visible: false,
            /*formatter:function(value,row,index){
                return "<a onclick='Home.homeDepartDetail(&apos;"+""+"&apos;,&apos;"+""+"&apos;)'>"+value+"</a>";
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMINum21");
            }
        },
        {title: '实施首次X线胸片检查数量', field: 'sTEMINum22', align: 'left', valign: 'middle', sortable: true,width:150, visible: false,
            /*formatter:function(value,row,index){
                return "<a onclick='Home.homeDepartDetail(&apos;"+""+"&apos;,&apos;"+""+"&apos;)'>"+value+"</a>";
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMINum22");
            }
        },
        {title: '完成 GRACE 评估的数量', field: 'sTEMINum23', align: 'left', valign: 'middle', sortable: true,width:150, visible: false,
            /*formatter:function(value,row,index){
                return "<a onclick='Home.homeDepartDetail(&apos;"+""+"&apos;,&apos;"+""+"&apos;)'>"+value+"</a>";
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMINum23");
            }
        },
        {title: '完成 CRUSADE 评估的数量', field: 'sTEMINum24', align: 'left', valign: 'middle', sortable: true,width:150, visible: false,
            /*formatter:function(value,row,index){
                return "<a onclick='Home.homeDepartDetail(&apos;"+""+"&apos;,&apos;"+""+"&apos;)'>"+value+"</a>";
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMINum24");
            }
        },
        {title: '使用首剂β-受体阻滞剂数量', field: 'sTEMINum4', align: 'left', valign: 'middle', sortable: true,width:150, visible: false,
            /*formatter:function(value,row,index){
                return "<a onclick='Home.homeDepartDetail(&apos;"+""+"&apos;,&apos;"+""+"&apos;)'>"+value+"</a>";
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMINum4");
            }
        },
        {title: '住院期间双联抗血小板药物使用数量', field: 'sTEMINum51', align: 'left', valign: 'middle', sortable: true,width:150, visible: false,
            /*formatter:function(value,row,index){
                return "<a onclick='Home.homeDepartDetail(&apos;"+""+"&apos;,&apos;"+""+"&apos;)'>"+value+"</a>";
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMINum51");
            }
        },
        {title: '住院期间β受体阻滞剂使用数量', field: 'sTEMINum52', align: 'left', valign: 'middle', sortable: true,width:150, visible: false,
            /*formatter:function(value,row,index){
                return "<a onclick='Home.homeDepartDetail(&apos;"+""+"&apos;,&apos;"+""+"&apos;)'>"+value+"</a>";
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMINum52");
            }
        },
        {title: '住院期间ACEI或ARB使用数量', field: 'sTEMINum53', align: 'left', valign: 'middle', sortable: true,width:150, visible: false,
            /*formatter:function(value,row,index){
                return "<a onclick='Home.homeDepartDetail(&apos;"+""+"&apos;,&apos;"+""+"&apos;)'>"+value+"</a>";
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMINum53");
            }
        },
        {title: '住院期间他汀类药物使用数量', field: 'sTEMINum54', align: 'left', valign: 'middle', sortable: true,width:150, visible: false,
            /*formatter:function(value,row,index){
                return "<a onclick='Home.homeDepartDetail(&apos;"+""+"&apos;,&apos;"+""+"&apos;)'>"+value+"</a>";
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMINum54");
            }
        },
        {title: '出院时双联抗血小板药物使用数量', field: 'sTEMINum61', align: 'left', valign: 'middle', sortable: true,width:150, visible: false,
            /*formatter:function(value,row,index){
                return "<a onclick='Home.homeDepartDetail(&apos;"+""+"&apos;,&apos;"+""+"&apos;)'>"+value+"</a>";
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMINum61");
            }
        },
        {title: '出院时β受体阻滞剂使用数量', field: 'sTEMINum62', align: 'left', valign: 'middle', sortable: true,width:150, visible: false,
            /*formatter:function(value,row,index){
                return "<a onclick='Home.homeDepartDetail(&apos;"+""+"&apos;,&apos;"+""+"&apos;)'>"+value+"</a>";
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMINum62");
            }
        },
        {title: '出院时ACEI或ARB使用数量', field: 'sTEMINum63', align: 'left', valign: 'middle', sortable: true,width:150, visible: false,
            /*formatter:function(value,row,index){
                return "<a onclick='Home.homeDepartDetail(&apos;"+""+"&apos;,&apos;"+""+"&apos;)'>"+value+"</a>";
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMINum63");
            }
        },
        {title: '出院时他汀类药物使用数量', field: 'sTEMINum64', align: 'left', valign: 'middle', sortable: true,width:150, visible: false,
            /*formatter:function(value,row,index){
                return "<a onclick='Home.homeDepartDetail(&apos;"+""+"&apos;,&apos;"+""+"&apos;)'>"+value+"</a>";
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMINum64");
            }
        },
        {title: '出院时醛固酮受体拮抗剂使用数量', field: 'sTEMINum65', align: 'left', valign: 'middle', sortable: true,width:150, visible: false,
            /*formatter:function(value,row,index){
                return "<a onclick='Home.homeDepartDetail(&apos;"+""+"&apos;,&apos;"+""+"&apos;)'>"+value+"</a>";
            },*/
            footerFormatter:function(value){
                return Home.sumFieldValue(value,"sTEMINum65");
            }
        }
    ]
]

/**
 * 科室详细信息
 */
Home.homeDepartDetail = function(dishDate,x){
    var qcEntity = $("#qcEntity").combobox("getValue");
    var qcEntityDesc = $("#qcEntity").combobox("getText");
    var qcYear = $("#qcYear").combobox("getValue");
    var qcMonth = $("#qcMonth").combobox("getValue");
    var office = $("#office").combobox("getValue");
    var depart = $("#depart").combobox("getValue");
    var href = "/api/detail?dishDate="+dishDate+"&qcEntity="+qcEntity+"&qcYear="+qcYear+"&qcMonth="+qcMonth+"&office="+office+"&depart="+depart+"&qcEntityDesc="+qcEntityDesc;
    layer.open({
        type: 2,
        title: ['<i class = "fa fa-list-ol"></i>&nbsp;'+qcEntityDesc+'详细','padding-left:10px'],
        area:["98%","98%"],
        scrollbar: false,//为了禁止父页面滚动条滚动
        skin:'classfyLBStyle layer-ext-hisui',
        content: href //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
    });

    //Sys.addTabPage($.trim(departDesc+"详细"), href,true);
};
/**
 * 钻取主页蓝色数字详细信息
 */
Home.homeKeyDetail = function(key,desc,type){
    //type=1是从顶部蓝色数字传入，type=2表示从下面表格传入，如果是钻取的科室，传area参数暂时定为主治医师Id
    var startDate = "";
    var endDate = "";
    /*if ($('#startDate').datebox('getValue') != ""){
        startDate = $('#startDate').datebox('getValue')+" 00:00:00";//开始日期
        endDate = $('#endDate').datebox('getValue')+" 23:59:59";//开始日期
    }*/
    var office = $("#office").combobox("getValue");
    var depart = $("#depart").combobox("getValue");
    var qcEntity = $("#qcEntity").combobox("getValue");

    if(type==2){
        var href = "/api/to_case2?key="+key+"&searchType=1&desc="+desc +"&startDate=" + startDate +"&endDate=" + endDate +"&office=" + office +"&depart=" + depart +"&qcEntity=" + qcEntity;
    }else{
        var href = "/api/to_case?key="+key+"&searchType=1&desc="+desc +"&startDate=" + startDate +"&endDate=" + endDate +"&office=" + office +"&depart=" + depart +"&qcEntity=" + qcEntity;
    }

    layer.open({
        type: 2,
        title: ['<i class = "fa fa-list-ol"></i>&nbsp;'+desc,'padding-left:10px'],
        area:["95%","95%"],
        scrollbar: false,//为了禁止父页面滚动条滚动
        skin:'classfyLBStyle layer-ext-hisui',
        content: href //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
    });
    //Sys.addTabPage($.trim(desc), href,true);

}

/**
 * 钻取主页蓝色数字详细信息
 */
Home.homeKeyDetailTable = function(key,desc,entityId){
    //type=1是从顶部蓝色数字传入，type=2表示从下面表格传入，如果是钻取的科室，传area参数暂时定为主治医师Id
    var startDate = "";
    var endDate = "";
    /*if ($('#startDate').datebox('getValue') != ""){
        startDate = $('#startDate').datebox('getValue')+" 00:00:00";//开始日期
        endDate = $('#endDate').datebox('getValue')+" 23:59:59";//开始日期
    }*/
    var office = $("#office").combobox("getValue");
    var depart = $("#depart").combobox("getValue");
    var qcEntity = $("#qcEntity").combobox("getValue");

    var href = "/api/to_case?key="+key+"&searchType=1&desc="+desc +"&startDate=" + startDate +"&endDate=" + endDate +"&office=" + office +"&depart=" + depart +"&qcEntity=" + qcEntity+"&entityId=" + entityId;

    layer.open({
        type: 2,
        title: ['<i class = "fa fa-list-ol"></i>&nbsp;'+desc,'padding-left:10px'],
        area:["95%","95%"],
        scrollbar: false,//为了禁止父页面滚动条滚动
        skin:'classfyLBStyle layer-ext-hisui',
        content: href //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
    });
    //Sys.addTabPage($.trim(desc), href,true);

}


/**
 * 绘制主页的表格
 */
Home.drawTable = function(tableData){
    this.$table =
        $('#departmentTable').bootstrapTable({
            data:tableData,
            striped: false,//是否显示行间隔色
            pagination: false,//是否显示分页
            showFooter: true,
            //paginationLoop: false,
            //pageSize : 5,//用于设置每页初始显示的条数
            //pageList :[4],
            //sidePagination: 'server',//设置在哪进行分页，默认”client”，可选”server”,返回数据模板不同
            sortName: "patientNum",
            sortOrder: 'desc',// desc  asc
            maintainSelected: true,//设为true 为选中的状态
            cache: false,
            search: false, //搜索框
            columns: Home.columns,
            /*classes:'abc',*/
            onPostHeader: function(){  //当<thead></thead>中的内容被加载完后或者在你所用的DOM中有定义则被触发
                // $(".th-inner").css("font-weight","700");//表头字体加粗
                $("#departmentTable > tbody td").each(function(index){//鼠标悬浮 显示表格数据
                    $(this).attr("title",$(this).text());
                });
            },
            onPostBody:function (tableData) {
                merge_footer();
            },
        });
};

/**
 * 导出主页的表格数据
 */
Home.exportTable = function() {
    $("#tableDiv table").tableExport(
        {
            type : 'xlsx',
            escape : 'false'
        },Home.getSystemTime()+Home.departDesc+'科室统计'
    )
};
/**
 * 获取当天年月日
 */
Home.getSystemTime = function(){
    function p(s) {
        return s < 10 ? '0' + s: s;
    }
    var date = new Date(); // 获取中国标准时间
    var y = date.getFullYear(); // 年
    var m = date.getMonth()+1; // 月
    var d = date.getDate(); // 日
    var sysTime = y+'-'+p(m)+'-'+p(d);
    return sysTime;
};
/**
 * 计算比率
 */
function MathMethod(a,b){
    if(b==0){
        return "0%";
    }
    var num = a/b;
    num = (num.toFixed(4)) * 100;  // 输出结果为 2.45
    var numStr = num.toString()
    var index = numStr.indexOf('.');
    if(index > -1){
        numStr = numStr.substring(0, index+3);
    }
    return numStr+"%";
}

Home.sumFieldValue = function(value,field){
    var disSum = 0;
    var count = 0;
    var tem = 0;
    if (field == "sTEMI1" || field == "sTEMI31" || field == "sTEMI32" || field == "sTEMI8" || field == "sTEMI9" || field == "sTEMI10" || field == "sTEMI11" || field == "sTEMI7"){
        for(var i in value){
            count += value[i][field]*1000;
        }
        disSum = value.length*1000;

        count = count/1000;
        disSum = disSum/1000;

        if (disSum == 0){
            return "";
        }
        return (count/disSum).toFixed(2);
    }else if (field == "num"){
        for(var i in value){
            count += parseInt(value[i][field]);
        }
        return count;
    } else {
        for(var i in value){
            /*if (value[i][field] == "y"){
                tem = 1;
            }*/
            count += value[i][field]*1000;
            disSum += parseInt(value[i]["num"])*1000;
        }
        //disSum = value.length*1000;
        count = count/1000;
        disSum = disSum/1000;

        if (disSum == 0){
            return "";
        }

        var pre = (count/disSum * 100).toFixed(2);
        return pre+"%&nbsp;&nbsp;("+count+")";
    }

};

function mergeCells(data,fieldName,colspan,target){
    //声明一个map计算相同属性值在data对象出现的次数和
    var sortMap = {};
    for(var i = 0 ; i < data.length ; i++){
        for(var prop in data[i]){
            if(prop == fieldName){
                var key = data[i][prop]     //fieldName的value
                if(sortMap.hasOwnProperty(key)){
                    sortMap[key] = sortMap[key] * 1 + 1;
                } else {
                    sortMap[key] = 1;
                }
                break;
            }
        }
    }
    /*for(var prop in sortMap){
        console.log(prop,sortMap[prop])
    }*/
    //合并单元格
    var index = 0;
    for(var prop in sortMap){
        var count = sortMap[prop] * 1;
        $(target).bootstrapTable('mergeCells',{index:index, field:fieldName, colspan: colspan, rowspan: count});
        index += count;
    }

}

//设置合计列宽度
function merge_footer(){
    //获取table表中footer 并获取到这一行的所有列
    var footer_tbody = $('.fixed-table-footer table tbody');
    var footer_tr = footer_tbody.find('>tr');
    var footer_td = footer_tr.find('>td');
    var footer_td_1 = footer_td.eq(0);
    for(var i=0;i<footer_td.length;i++){
        footer_td.eq(i).hide();//隐藏单元格
        if(i >= 0 && i <= 1){
            footer_td.eq(i).attr('width', "80px").show();//显示单元格并设置列宽
        }else {
            footer_td.eq(i).attr('width', "150px").show();//显示单元格并设置列宽
        }
    }
}